import request from 'axios';

import { RELOAD_MOCK_SERVER_TRIGGER, SET_SERVER_TIME_TRIGGER, PUSH_CODE_SERVER } from '../reducers/api-mock-state.js';

/**
 * 重启 API Mock 服务
 * @param  {Object}     props
 * @return {Object}
 */
export function reloadMockServer() {
    return {
        type: RELOAD_MOCK_SERVER_TRIGGER,
        via: 'ws'
    };
}

/**
 * push code to coding.net
 * @param  {Object}     props
 * @return {Object}
 */
export function pushCodeServer() {
    return {
        type: PUSH_CODE_SERVER,
        payload: {
            promise: request.post(`/action/pushCode`,
                {
                    time: 1480924590422
                })
                .then(response => response.data)
        }
    };
}

/**
 * 设置服务器时间
 * @param  {Object}     props
 * @return {Object}
 */
export function setTimeServer() {
    return {
        type: SET_SERVER_TIME_TRIGGER,
        via: 'ws',
        payload: {
            time: 1480924590422
        }
    };
}
